<template>
    <el-select v-model="scope.row.costCenter" @visible-change="visibleChange"
               filterable
               @change="costCenterChange" placeholder="请选择">
        <el-option
            v-for="(item, index) in list"
            :key="index"
            :label="item.description"
            :value="item.flexValueId">
        </el-option>
    </el-select>
</template>
<script>
import { applyUpdateMaterial } from "../../../components/axios/url";
import http from "../../../components/axios/fetch";

    export default {
        name: "cost-center-select",
        data(){
            return{
                list:[]
            }
        },
        props: {
            scope: {},
            costCenterList:{default:[]}
        },
        mounted(){
        },
        methods: {
            visibleChange(value) {
                if(value)
                    this.list = this.costCenterList;
            },
            costCenterChange(event) {
                console.log(event)
                let param = {
                    id: this.scope.row.id,
                    costCenterId: event
                }
                try{
                    http.post(applyUpdateMaterial, param).then(res => {
                        if(res.data && res.data.resultMess === "success") {
                            this.$emit('getMaterialList');
                            this.$notify({
                                title: '提示',
                                message: '修改成功',
                                type: 'success'
                            });
                        }
                    })
                }catch(error){
                    this.$notify.error({
                        title: '提示',
                        message: '网络错误',
                    });
                }
            }

        }
    }
</script>

<style scoped>

</style>
